﻿using ASoft.WPF.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ASoft.WPF.View
{
    /// <summary>
    /// RoomDataListControl.xaml 的交互逻辑
    /// </summary>
    public partial class RoomDataListControl : UserControl
    {
        public RoomDataListControl()
        {
            InitializeComponent();
            tabControl.Items.RemoveAt(0);
        }

        private void ListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var item = ((ListBox)sender).SelectedItem;
            if (item != null)
            {
                var frm = new RoomDetailView();
                frm.DataContext = item;
                frm.ShowDialog();
                //(this.DataContext as MainViewModel).Reload温室实时数据集合();
            }
        }

        private void ListView_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var item = ((ListView)sender).SelectedItem;
            if (item != null)
            {
                var frm = new RoomDetailView();
                frm.DataContext = item;
                frm.ShowDialog();
                //(this.DataContext as MainViewModel).Reload温室实时数据集合();
            }
        }

        private void RoomAllControl_RoomChanged(object sender, EventArgs e)
        {
            //listViewDetail.SelectedItem = ((RoomAllControl)sender).CurrentRoom;
            roomSingleControl.DataContext = ((RoomAllControl)sender).CurrentRoom;
            tabControlItem.IsSelected = true;
            //tabControl.SelectedItem = tabControlItem;
        }

        private void listViewDetail_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var listView = sender as ListView;
            if (listView.SelectedItem != null)
                listView.ScrollIntoView(listView.SelectedItem);
        }
    }
}
